put the loc of cd btn 1 into line 1 of INITIAL_LOC
put the loc of cd btn 2 into line 2 of INITIAL_LOC
pass OpenCard
end OpenCard
on CloseCard
global INITIAL_LOC
set the loc of cd btn 1 to line 1 of INITIAL_LOC
set the loc of cd btn 2 to line 2 of INITIAL_LOC
pass CloseCard
end CloseCard
on hideObjects
hide cd btn 1
hide cd btn 2
hide cd fld "label"
end hideObjects
on showObjects
show cd btn 1
show cd btn 2
show cd fld "label"
end showObjects
-- part 2 (field)
-- low flags: 01
-- high flags: 0000
-- rect: left=28 top=171 right=207 bottom=212
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 3
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: label
-- part 3 (button)
-- low flags: 00
-- high flags: 8004
-- rect: left=22 top=279 right=310 bottom=210
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: DragRect(rect of me, "NoClipping")
----- HyperTalk script -----
on mouseDown
put the rect of me into buttonRect
put the loc of me into myLoc
put DragRect(the rect of me, "noclipping") into locOffset
--
-- convert HC window location to local coords
put the rect of cd window into windowRect
put OffsetRect(-(item 1 of windowRect), -(item 2 of windowRect), windowRect) into windowRect
--
-- what will the rect of the button be now?
put OffsetRect(item 1 of locOffset, item 2 of locOffset, buttonRect) into buttonRect
--
-- make a slightly smaller than actual size rect (small safety
-- margin) for the new button so that we can test to see if it
-- will end up off-screen if we move it
put item 1 of buttonRect + 5 & "," & item 2 of buttonRect + 5 into topLeft
put item 3 of buttonRect - 5 & "," & item 4 of buttonRect - 5 into botRight
put item 3 of buttonRect - 5 & "," & item 2 of buttonRect + 5 into topRight
put item 1 of buttonRect + 5 & "," & item 4 of buttonRect - 5 into botLeft
--
-- see if the button was released offscreen
if (topLeft is not within windowRect) and (botRight is not within windowRect) and (topRight is not within windowRect) and (botLeft is not within windowRect) then
answer "This button can't be moved outside of HC's window."
else
add item 1 of locOffset to item 1 of myLoc
add item 2 of locOffset to item 2 of myLoc
set the loc of me to myLoc
end if
end mouseDown
function OffsetRect deltaX, deltaY, origRect
-- offset a rectangle, useful for converting between local (within
-- HC's card window) and global coordinates
add deltaX to item 1 of origRect
add deltaX to item 3 of origRect
add deltaY to item 2 of origRect
add deltaY to item 4 of origRect
return origRect
end OffsetRect
-- part 4 (button)
-- low flags: 00
-- high flags: 8004
-- rect: left=44 top=223 right=254 bottom=183
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: DragRect(rect of me)
----- HyperTalk script -----
on mouseDown
put the rect of me into buttonRect
put the loc of me into myLoc
put DragRect(rect of me) into locOffset
--
-- convert HC window location to local coords
put the rect of cd window into windowRect
put OffsetRect(-(item 1 of windowRect), -(item 2 of windowRect), windowRect) into windowRect
--
-- what will the rect of the button be now?
put OffsetRect(item 1 of locOffset, item 2 of locOffset, buttonRect) into buttonRect
--
-- make a slightly smaller than actual size rect (small safety
-- margin) for the new button so that we can test to see if it
-- will end up off-screen if we move it
put item 1 of buttonRect + 5 & "," & item 2 of buttonRect + 5 into topLeft
put item 3 of buttonRect - 5 & "," & item 4 of buttonRect - 5 into botRight
put item 3 of buttonRect - 5 & "," & item 2 of buttonRect + 5 into topRight
put item 1 of buttonRect + 5 & "," & item 4 of buttonRect - 5 into botLeft
--
-- see if the button was released offscreen
if (topLeft is not within windowRect) and (botRight is not within windowRect) and (topRight is not within windowRect) and (botLeft is not within windowRect) then
answer "The button can't be moved outside of HC's window."
else
add item 1 of locOffset to item 1 of myLoc
add item 2 of locOffset to item 2 of myLoc
set the loc of me to myLoc
end if
end mouseDown
function OffsetRect deltaX, deltaY, origRect
-- offset a rectangle, useful for converting between local (within
-- HC's card window) and global coordinates
add deltaX to item 1 of origRect
add deltaX to item 3 of origRect
add deltaY to item 2 of origRect
add deltaY to item 4 of origRect
return origRect
end OffsetRect
-- part contents for background part 38
----- text -----
12/50
-- part contents for card part 2
----- text -----
Drag the button below to see an example of DragRect
-- part contents for background part 20
----- text -----
An XFCN which drags a gray rectangle around the screen as the mouse is moved. The XFCN returns the distance between the original rectangle (the XFCN's parameter) and the final rectangle (the point at which the mouse button was released). The XFCN keeps control until the mouse button is released.
If the optional second parameter contains the literal string ΓÇ£NOCLIPPINGΓÇ¥ the rect can be dragged anywhere on the screen, otherwise the rect can not be dragged outside of the rect of the card window. Look at the buttons on the right for examples.